<template>
	<view class="content">
		<view class="cu-list menu-avatar solid-top bg-white">
			<view class="response solid-bottom flex padding-lr padding-tb-sm flex-wrap" style="padding-right: 30upx;" v-for="item in list" :key="item.name">
				<view class="left-block flex flex-direction align-center">
					<view class="response text-df">{{item.title}}<text v-if="item.status == 0" class="text-sm" :class="{'text-blue':item.state == 0,'text-green':item.state == 1,'text-gray':item.state == 2,'text-red':item.state == 3}">({{item.zt}})</text></view>
					<view class="response text-sm text-gray margin-top-sm">{{item.createdTime}}</view>
				</view>
				<view class="right-block flex justify-end align-center">
					<view class="response text-right text-bold text-xl" :class="{'text-red' : item.status > 1 }">{{ item.icon + (item.state == 3 ? 0 :item.integral)}}</view>
				</view>
				<view v-if="item.state == 3" class="response text-red text-sm padding-tb-xs">失败原因:{{item.failMsg}}</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadingType: 'more',
				page: 1,
				limit: 10,
				list: []
			}
		},
		onLoad() {
			this.getList();
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.loadData('refresh');
		},
		//加载更多
		onReachBottom() {
			this.loadData("add");
		},
		methods: {

			//加载商品 ，带下拉刷新和上滑加载
			loadData(type) {
				//没有更多直接返回

				if (type === 'add') {
					if (this.loadingType === 'nomore') {
						return;
					}
					this.loadingType = 'loading';
				} else {
					this.loadingType = 'more'
				}
				var that = this;
				that.page = that.page + 1;

				if (type === 'refresh') {
					this.list = [];
					this.page = 1;
				}

				if (type === 'refresh') {
					uni.stopPullDownRefresh();
				}
				that.getList();
			},
			getList() {
				if (this.loadingType == 'nomore') {
					return;
				}
				var that = this;
				that.$network.request("UserAction/integralRecord", {
					page: that.page,
					limit: that.limit
				}, function(res) {
					let list = that.list;
					var resList = res.data.list;
					for(var i in resList){
						resList[i].title = that.getTitle(resList[i].status);
						resList[i].zt = that.getState(resList[i].state);
						resList[i].icon = resList[i].status <= 1 ? "-" : "+";
					}
					that.list = list.concat(resList);
					if (res.data.list == 0 || that.list.length < that.limit) {
						that.loadingType = 'nomore';
						return;
					}
				}, "", function(res) {
					console.error(JSON.stringify(res))
					uni.showToast({
						icon: 'none',
						title: '加载失败',
						duration: 1200
					})
				});
			},
			getTitle(status){
				if(status == 0){
					return '提现';
				}else if(status == 1){
					return '消费';
				}else if(status == 2){
					return '挂售收入';
				}else if(status == 3){
					return '互动收入';
				}else{
					return '代理收入';
				}
			},getState(state){
				if(state == 0){
					return '审核中';
				}else if(state == 1){
					return '审核通过';
				}else if(state == 2){
					return '已打款';
				}else{
					return '提现失败';
				}
			}
			
		}
	}
</script>

<style>
	.left-block{
		width: 60%;
	}
	.right-block{
		width: 40%;
	}
</style>
